import request from '@/utils/request.js'
// import store from '@/store'
// 定义所有频道的接口，一个接口一个函数
// 获取标题
export const getAllChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
// 登陆验证
export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}
// 获取用户已选的标题列表
export const getUserChannelsAPI = () => {
  return request({
    meththod: 'GET',
    url: '/v1_0/user/channels'
    //   headers: {
    //     Authorization: `Bearer ${store.state.token}`
    //   }
  })
}
// 获取文章列表
export const articlesListAPI = ({ channelId, timestamp = Date.now() + '' }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}
// 删除不感兴趣文章
export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    }
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // }
  })
}
// 文章举报接口
export const articleReportsAPI = ({ artId, type, remark }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/reports',
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },
    data: {
      target: artId,
      type,
      remark: type === '0' ? remark : remark || null
    }
  })
}

// 更新用户已选频道
export const userCheckChannelAPI = ({ channels }) => {
  return request({
    method: 'PUT',
    url: '/v1_0/user/channels',
    data: {
      channels
    }
  })
}
// 搜索建议
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}
// 搜索结果页请求
export const searchResultListAPI = ({ q, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q,
      page
    }
  })
}
// 详情页请求
export const articleDetailAPI = ({ id }) => {
  return request({
    // :id是后台规定的参数名
    // 前端要在对应路径位置传值(不要写:)
    url: `/v1_0/articles/${id}`
  })
}
